package com.example.chatchatbackend.Controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.chatchatbackend.entity.RestBean;
import com.example.chatchatbackend.entity.dto.Adv;
import com.example.chatchatbackend.entity.dto.Comments;
import com.example.chatchatbackend.entity.dto.Comments;
import com.example.chatchatbackend.entity.vo.request.AdvVO;
import com.example.chatchatbackend.entity.vo.request.CommentsVO;
import com.example.chatchatbackend.service.AdvService;
import com.example.chatchatbackend.service.CommentsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 丁真
 * @since 2024-10-28 05:03:47
 */

@Slf4j
@RestController
@RequestMapping("/api/comments")
public class CommentsController {


    @Autowired
    private CommentsService commentsService;

    @GetMapping
    public RestBean<List<CommentsVO>> getAllComment(){
        return RestBean.success(commentsService.getAllComments());
    }

    @PostMapping
    public RestBean<CommentsVO> insertAdv(@RequestBody CommentsVO commentsVO){
        CommentsVO insertCommentsVO = commentsService.insertComments(commentsVO);
        return RestBean.success(insertCommentsVO);

    }

    @PostMapping("/list")
    public RestBean<List<CommentsVO>> insertAdvList (@RequestBody List<CommentsVO> commentsVO){
        List<CommentsVO> CommentsList = commentsService.insertCommentsList(commentsVO);
        return RestBean.success(CommentsList);
    }

    @GetMapping("/pageThree")
    public RestBean<IPage<Comments>> pageThree(@RequestParam(value = "pageNum" ,defaultValue = "1") Integer pageNum,
                                               @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize){
        return RestBean.success(commentsService.pageThree(pageNum, pageSize));
    }


    @DeleteMapping("/ids")
    public RestBean<String> delete(@RequestBody List<Integer> ids) {
        commentsService.deleteByIds(ids);
        return RestBean.success("删除成功");
    }


}
